package com.henghai.zhenxuan.ui.page.adapter;

import android.content.Context;

import androidx.recyclerview.widget.RecyclerView;

import com.henghai.zhenxuan.data.bean.AddressBean;
import com.henghai.zhenxuan.databinding.AdapterAddressItemBinding;
import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter;

public class AddressListAdapter extends SimpleDataBindingAdapter<AddressBean, AdapterAddressItemBinding> {

    public AddressListAdapter(Context context) {
        super(context, com.henghai.zhenxuan.R.layout.adapter_address_item, DiffUtils.getInstance().getAddressItemCallback());
    }

    @Override
    protected void onBindItem(AdapterAddressItemBinding adapterTaskItemBinding, AddressBean taskBean, RecyclerView.ViewHolder viewHolder) {
        adapterTaskItemBinding.setAddress(taskBean);
        adapterTaskItemBinding.addressDel.setOnClickListener(v -> mItemBtClickListener.onItemDelClick(taskBean, viewHolder.getBindingAdapterPosition()));
        adapterTaskItemBinding.addressEdit.setOnClickListener(v -> mItemBtClickListener.onItemEditClick(taskBean, viewHolder.getBindingAdapterPosition()));
        adapterTaskItemBinding.isDefaultCb.setOnClickListener(v -> mItemBtClickListener.onItemDefaultClick(taskBean, adapterTaskItemBinding.isDefaultCb.isChecked()));
    }

    private OnItemBtClickListener mItemBtClickListener;

    public void setOnItemBtClickListener(OnItemBtClickListener l) {
        this.mItemBtClickListener = l;
    }

    public interface OnItemBtClickListener {

        void onItemDelClick(AddressBean taskBean, int position);

        void onItemEditClick(AddressBean taskBean, int position);

        void onItemDefaultClick(AddressBean taskBean, boolean isChecked);
    }
}
